package com.nepxion.discovery.plugin.registercenter.kubernetes.adapter;

/**
 * <p>Title: Nepxion Discovery</p>
 * <p>Description: Nepxion Discovery</p>
 * <p>Copyright: Copyright (c) 2017-2050</p>
 * <p>Company: Nepxion</p>
 * @author cosmos
 * @version 1.0
 */

import java.util.Map;

import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesServiceInstance;
import org.springframework.cloud.kubernetes.fabric8.registry.KubernetesRegistration;

import com.nepxion.discovery.plugin.framework.adapter.AbstractPluginAdapter;

public class KubernetesAdapter extends AbstractPluginAdapter {
    @Override
    public Map<String, String> getMetadata() {
        if (registration instanceof KubernetesRegistration) {
            KubernetesRegistration kubernetesRegistration = (KubernetesRegistration) registration;

            return kubernetesRegistration.getProperties().getServiceLabels();
        }

        return emptyMetadata;
    }

    @Override
    public Map<String, String> getServerMetadata(ServiceInstance server) {
        if (server instanceof KubernetesServiceInstance) {
            KubernetesServiceInstance kubernetesServer = (KubernetesServiceInstance) server;

            return kubernetesServer.getMetadata();
        }

        return emptyMetadata;

        // throw new DiscoveryException("Server instance isn't the type of KubernetesServer");
    }
}